﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Best.SmartCms.Utility
{
    /// <summary>
    /// 数字类型帮助类
    /// </summary>
    public static class NumberHelper
    {
        /// <summary>
        /// double 转字符串
        /// </summary>
        /// <param name="number"></param>
        /// <param name="decimals"></param>
        /// <returns></returns>
        public static string DoubleToString(this double? number, int decimals = 6)
        {
            return DoubleToString(number.GetValueOrDefault(),decimals);
        }


        /// <summary>
        /// double 转字符串
        /// </summary>
        /// <param name="number"></param>
        /// <param name="decimals"></param>
        /// <returns></returns>
        public static string DoubleToString(this double number, int decimals = 6)
        {
            return Math.Abs(number) <= 0.0 ? "0" : number.ToString($"f{decimals}");
        }


    
    }
}
